﻿using Newtonsoft.Json.Linq;
using NPortableEngine;
using Services4KouDai.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Services4KouDai.Parsers
{
    public class ShopParser : IParser
    {
        public override void ParseJson(string json, BackData backData)
        {
            List<ShopEntity> shops = (List<ShopEntity>)backData.ResponseData;
            JObject jobj = JObject.Parse(json);

            JToken jt = jobj.SelectToken("result");
            foreach (JToken subJt in jt.Children())
            {
                var shop = new ShopEntity();
                shop.AbbreviatedImageUrl = subJt.Value<string>("abbreviatedImageUrl");
                shop.AppName = subJt.Value<string>("appName");
                shop.Description = subJt.Value<string>("description");
                shop.EntranceName = subJt.Value<string>("entranceName");
                shop.FavoriteAmount = subJt.Value<int>("favoriteAmount");
                shop.ImageUrl = subJt.Value<string>("imgUrl");
                shop.Remarks = subJt.Value<string>("remarks");
                shop.Score = subJt.Value<int>("score");
                shop.ShopGrade = subJt.Value<string>("shopGrade");
                shops.Add(shop);
            }
        }
    }
}
